export class Observer {
   //通知
   private _callBack: Function = null ;
   //通知函数的上下文
   private _context: any = null;
   //监听一次
   private _once: boolean = false;

   public get isOnce(): boolean { return this._once }

   constructor(callback: Function, context: any, once: boolean) {
        this._callBack = callback;
        this._context = context;
        this._once = once;
   }

   /**
     * 发送通知
     * @param args 不定参数
     */
    public async notify(...args: any[]) {
        console.log('notify',...args);
      return this._callBack.call(this._context, ...args)
  }
  /**
   * 判断该观察者内的上下文和回调方法与传入的是否相同（如果没传入回调方法则只比较上下文）
   * @param callback 
   * @param context 
   */
  public compar(callback: Function, context: any): boolean {
      if (callback) {
          return context == this._context && callback == this._callBack
      } else {
          return context == this._context
      }
  }
}